/*
* commentsview.h - This file is the part of the wp-notifier.(code name "luan luan")
* Copyright (C) 2010 Dean Lee <deanlee3@gmail.com>, http://www.deanlee.cn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
* Acknowledgements:
*   <> Many thanks to all of you, who have encouraged me to update my articles
*     and code, and who sent in bug reports and fixes.
* 
*/
#ifndef COMMENTSVIEW_H
#define COMMENTSVIEW_H
#include <QStyledItemDelegate>
#include <QListView>
#include <QTextEdit>
#include "wpxmlrpc.h"


class CommentItemDelegate : public QStyledItemDelegate
{
	Q_OBJECT
public:
	CommentItemDelegate(QObject* parent = NULL);
	~CommentItemDelegate();
	void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
	QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const;
protected:
	bool eventFilter(QObject * editor, QEvent * event);
	void drawCommentContent(QPainter *p, const QStyleOptionViewItemV4 *option, const QRect &rect, const QString& text)const;
};

class CommentsView : public QListView
{
	Q_OBJECT
public:
	CommentsView(QWidget* parent = NULL);
	~CommentsView();
	void setModel(QAbstractItemModel * model);
signals:
	void replyComment(const QModelIndex&);
public slots:
	void actDelete();
	void actReply();
	void actApprove();
	void actHold();
	void actSpam();
	void actEdit();
protected slots:
	void filterChanged(CommentData::CommentStatus);
	void commandClicked(const QString&);
	void editorDestroyed(QObject * editor);
	void currentChanged ( const QModelIndex & current, const QModelIndex & previous );
protected:
	void keyPressEvent(QKeyEvent * event);
	void setSelectedCommentsStatus(CommentData::CommentStatus status);
	void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
	void contextMenuEvent ( QContextMenuEvent * e );
	void scrollContentsBy ( int dx, int dy );
	void resizeEvent(QResizeEvent *e);
	enum MousePosition
	{none, author, postTitle};

	void leaveEvent ( QEvent * event );
	void mouseMoveEvent(QMouseEvent *event);
	void mousePressEvent(QMouseEvent *event);
	void showCommandBar();
	bool edit ( const QModelIndex & index, EditTrigger trigger, QEvent * event );
	QLabel *m_commandBar;
	MousePosition m_mousePosition;
	//QModelIndex m_editingIndex;
};

class LineEdit : public QTextEdit
{
	Q_OBJECT
public:
	LineEdit(QWidget* parent);
	~LineEdit();

	// reimplemented
	QSize minimumSizeHint() const;
	QSize sizeHint() const;

protected:
	void resizeEvent(QResizeEvent*);

	private slots:
		void recalculateSize();
		void updateScrollBar();
};

#endif

